import 'package:flutter/material.dart';
import 'package:flutter_app/pages/home/home_one.dart';
import 'package:flutter_app/pages/information/index.dart';
import 'package:flutter_app/pages/my/index.dart';
import 'package:flutter_app/pages/search/index.dart';

/// @description: 首页底部tabbar

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<Widget> _tabbarList = [
    const HomeOne(),
    const SearchPage(),
    const Informationpage(),
    const MyPage(),
  ];
  final List<BottomNavigationBarItem> _navigationBarItem = [
    const BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: '首页',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.search),
      label: '搜索',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.info),
      label: '资讯',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.account_circle),
      label: '我的',
    ),
  ];
  int _selectedIndex = 0;
  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _tabbarList[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: _navigationBarItem.map((e) => (e)).toList(),
        type: BottomNavigationBarType.fixed,
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.green[800],
        onTap: _onItemTapped,
      ),
    );
  }
}
